from conductance_neuron import Conductance_neuron
from alpha_synapse import Alpha_synapse
from scipy.integrate import odeint
from scipy import linspace,arange
from pylab import plot,show,subplot


# make the model neuron
c = Conductance_neuron(g_leak = 3.0, E_leak = -56.4, tau = 100, V_init = -50.0)

#----------------------------------------------------------------------------------
# without registering any extra inputs/currents, let's see how this model behaves.
#----------------------------------------------------------------------------------
# get the initial values of the state variables
sv_init = c.get_sv_init_list()

t = arange(0,200,0.1) # time steps of 0.1 ms for 1 second
sv_results = odeint(c.dX_dt, sv_init, t)

# plot the results, notice that the voltage decays to the resting voltage (E_leak)
subplot(311)
plot(t,sv_results)

#----------------------------------------------------------------------------------
# recreate hyperpolarization data
#----------------------------------------------------------------------------------
def c_input(sv,t):
    """ Just a rectangular current pulse, result is in nA """
    if t > 500 and t < 1500:
        return -0.02
    else:
        return 0

c.register_input("step",c_input)

# get the initial values of the state variables
sv_init = c.get_sv_init_list()

t = arange(0,2000,0.1) # time steps of 0.1 ms for 1 second
sv_results = odeint(c.dX_dt, sv_init, t)

# plot the results, notice that the voltage decays to the resting voltage (E_leak)
subplot(312)
plot(t,sv_results)

#----------------------------------------------------------------------------------
# some synaptic input
#----------------------------------------------------------------------------------
c2 = Conductance_neuron(g_leak = 3.0, E_leak = -56.5, tau = 100, V_init = -56.5)

c2.register_input("E",Alpha_synapse(onset=14.5,tau=3.0,gmax=0.006,E_rev=10.0))
c2.register_input("I",Alpha_synapse(onset=11,tau=8.5,gmax=0.0175,E_rev=-79.0))

sv_init = c2.get_sv_init_list()

t = arange(0,500,0.1)
sv_results = odeint(c2.dX_dt, sv_init, t)

subplot(313)
plot(t,sv_results)
show()

